package aygx.enable.registrar;

import aygx.enable.entity.Account;
import aygx.enable.entity.Role;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author 暗影孤星
 * @date 2020/10/28 23:18
 * @explanation
 */
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        registry.registerBeanDefinition("account", BeanDefinitionBuilder.rootBeanDefinition(Account.class).getBeanDefinition());
        // 当已经有这个bean时 再注册获取时会报错
        registry.registerBeanDefinition("role2", BeanDefinitionBuilder.rootBeanDefinition(Role.class).getBeanDefinition());
    }
}
